package com.v.air.app.adapter;

import java.util.ArrayList;
import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.v.air.app.R;
import com.v.air.app.bean.DeviceBean;

public class DeviceAdapter extends BaseAdapter {
	private List<DeviceBean> data = new ArrayList<DeviceBean>();
	private LayoutInflater inflater;

	public DeviceAdapter(Context context) {
		this.inflater = LayoutInflater.from(context);
	}

	public List<DeviceBean> getData() {
		return data;
	}

	public void setData(List<DeviceBean> data) {
		this.data = data;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return data.get(position);
	}

	@Override
	public long getItemId(int id) {
		// TODO Auto-generated method stub
		return id;
	}

	public class ViewHolder {
		private LinearLayout layout;
		private TextView nameTextView;
		private TextView pmTextView;
		private TextView weiTextView;
		private TextView shiTextView;
		private TextView coTextView;
		private TextView tvocTextView;
	}

	@SuppressLint("ResourceAsColor")
	public View getView(final int position, View contentView, ViewGroup arg2) {
		ViewHolder holder = null;
		if (contentView == null) {
			holder = new ViewHolder();
			contentView = inflater.inflate(R.layout.device_item, null);
			holder.layout = (LinearLayout) contentView
					.findViewById(R.id.layout_title_bottom);
			holder.nameTextView = (TextView) contentView
					.findViewById(R.id.name);
			holder.pmTextView = (TextView) contentView.findViewById(R.id.pm);
			holder.weiTextView = (TextView) contentView.findViewById(R.id.wei);
			holder.shiTextView = (TextView) contentView.findViewById(R.id.shi);
			holder.coTextView = (TextView) contentView.findViewById(R.id.co2);
			holder.tvocTextView = (TextView) contentView
					.findViewById(R.id.tvoc);
			contentView.setTag(holder);
		} else {
			holder = (ViewHolder) contentView.getTag();
		}
//		holder.layout .setBackgroundColor(R.color.color_right_bottom_list);
		final DeviceBean bean = data.get(position);
		holder.nameTextView.setText(bean.getName());
		holder.pmTextView.setText(String.valueOf(bean.getPm()));
		holder.weiTextView.setText(String.valueOf(bean.getTemperature()));
		holder.shiTextView.setText(String.valueOf(bean.getHumidity()));
		holder.coTextView.setText(String.valueOf(bean.getPpm()));
		holder.tvocTextView.setText(String.valueOf(bean.getTvoc()));
		return contentView;
	}
}
